package com.example.hello_app.config;

import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Knife4jConfig {

    @Bean
    public GroupedOpenApi api() {
        return GroupedOpenApi.builder()
                .group("默认分组")
                .packagesToScan("com.example.hello_app.controller") // 扫描的包路径
                .pathsToMatch("/**")
                .addOpenApiCustomizer(openApi -> openApi.info(apiInfo()))
                .build();
    }

    private Info apiInfo() {
        return new Info()
                .title("示例项目接口文档")
                .description("这是示例项目的接口文档")
                .version("1.0.0")
                .contact(new Contact().name("开发者").email("developer@example.com"))
                .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"));
    }
}
